package com.py.androidUtils.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.readyidu.app.R;

/**
 * @说明 数据加载界面
 * @作者 LY
 * @文件 LoadingDataEemptyView.java
 * @时间 2015年6月18日 下午4:29:17
 * @版权 Copyright(c) 2014 LY-版权所有
 */
public class LoadDataEemptyView extends FrameLayout {
	private LinearLayout loadData;
	private LinearLayout netWork;
	private LinearLayout loadEmpty;
	private IClickLoadListener clickLoadListener;

	public LoadDataEemptyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	/**
	 * 初始化界面
	 */
	@SuppressLint("InflateParams")
	private void initView(Context context) {
		View view = LayoutInflater.from(context).inflate(R.layout.common_load_data_empty, null);
		loadData = (LinearLayout) view.findViewById(R.id.loadData);
		netWork = (LinearLayout) view.findViewById(R.id.netWork);
		loadEmpty = (LinearLayout) view.findViewById(R.id.loadEmpty);
		addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	}

	/**
	 * 数据加载中
	 */
	public void loadData() {
		loadData.setVisibility(View.VISIBLE);
		netWork.setVisibility(View.GONE);
		loadEmpty.setVisibility(View.GONE);
	}

	/**
	 * 网络连接出错
	 */
	public void netWorkError() {
		loadData.setVisibility(View.GONE);
		netWork.setVisibility(View.VISIBLE);
		loadEmpty.setVisibility(View.GONE);
		netWork.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				clickLoadListener.settingNetWork();
			}
		});
	}

	/**
	 * 数据加载失败
	 */
	public void loadEmptyError() {
		loadData.setVisibility(View.GONE);
		netWork.setVisibility(View.GONE);
		loadEmpty.setVisibility(View.VISIBLE);
		loadEmpty.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				clickLoadListener.load();
			}
		});
	}

	/**
	 * 点击屏幕加载数据
	 */
	public interface IClickLoadListener {
		public void load();

		public void settingNetWork();
	}

	public void setClickLoadListener(IClickLoadListener clickLoadListener) {
		this.clickLoadListener = clickLoadListener;
	}
}
